package timing.ukulele.flow.controller;

import timing.ukulele.flow.service.ModelService;
import timing.ukulele.flow.vo.BpmnModelVO;
import timing.ukulele.common.ResponseResult;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("model")
@Api(tags = "流程模型接口")
public class ModelController {

    private final ModelService modelService;

    public ModelController(ModelService modelService) {
        this.modelService = modelService;
    }

    @PostMapping("/save")
    @ApiOperation("保存模型")
    public ResponseResult<String> saveBpmn(@RequestBody BpmnModelVO bpmn) {
        return modelService.saveBpmn(bpmn);
    }

    @GetMapping("/getById/{modelId}")
    @ApiOperation("根据模型id获取模型bpmn的xml字符串")
    public ResponseResult<String> getBpmnXmnById(@ApiParam(value = "bpmn模型id", required = true) @PathVariable("modelId") String modelId) {
        return modelService.getBpmnXmnById(modelId);
    }

    @PostMapping(path = "/createFlowModel")
    @ApiOperation(value = "创建或更新流程模型", notes = "创建或更新流程模型")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tenantId", value = "租户id", dataType = "String", paramType = "query", example = ""),
            @ApiImplicitParam(name = "modelId", value = "流程模型id", dataType = "String", paramType = "query", example = ""),
            @ApiImplicitParam(name = "processKey", value = "流程key", dataType = "String", paramType = "query", example = ""),
            @ApiImplicitParam(name = "category", value = "流程分类", dataType = "String", paramType = "query", example = ""),
            @ApiImplicitParam(name = "processName", value = "流程模型名称", dataType = "String", paramType = "query", example = ""),
            @ApiImplicitParam(name = "processDescription", value = "流程模型描述", dataType = "String", paramType = "query", example = ""),
            // @ApiImplicitParam(name = "json_xml", value = "jsonXml", dataType = "String", paramType = "query", example = ""),
            // @ApiImplicitParam(name = "svg_xml", value = "svgXml", dataType = "String", paramType = "query", example = ""),
    })
    public ResponseResult createFlowModel(@RequestParam("tenantId") String tenantId,
                                          @RequestParam("modelId") String modelId,
                                          @RequestParam("processKey") String processKey,
                                          @RequestParam("category") String category,
                                          @RequestParam("processName") String processName,
                                          @RequestParam("processDescription") String processDescription,
                                          @RequestBody String jsonXml) {
        return modelService.createFlowModel(tenantId, modelId, processKey, category, processName, processDescription, jsonXml);
    }
}
